const _ = require('lodash')
require('deepdash')(_); // mixin Deepdash methods into Lodash

let things = {
    things: [
      { name: 'something', good: false },
      {
        name: 'another thing', good: true,
        children: [
          { name: 'child thing 1', good: false },
          { name: 'child thing 2', good: true },
          { name: 'child thing 3', good: false },
        ],
      },
      {
        name: 'something else', good: true,
        subItem: { name: 'sub-item', good: false },
        subItem2: { name: 'sub-item-2', good: true },
      },
    ],
  };


console.log('Source Data',things, true);

let filtrate = _.filterDeep(
    things,
    (value, key, parent) => {
      if (key == 'name' && parent.good) return true;
      if (key == 'good' && value == true) return true;
    }
  );


console.log(`'key == 'name' && parent.good
key == 'good' && value == true`, filtrate);



































// boring stuff
var consoleEl;
var consoleN=0;

function log(title, txt, collapsed){
  if(!consoleN)
    consoleN=1
  else
    consoleN++;
  if(!consoleEl){
    consoleEl = document.getElementById('console');
  }
  var toggleEl = document.createElement("input");
  toggleEl.setAttribute('type','checkbox');
  toggleEl.setAttribute('id','con-'+consoleN);
  toggleEl.checked=!collapsed;
  var titleEl = document.createElement("div");
  titleEl.classList.add('title');
  titleEl.innerHTML = '<label for="con-'+consoleN+'"><span class="expand">›››</span><span class="collapse">‹‹‹</span>'+' '+title+'<span class="expand">...</span></label>';
  consoleEl.appendChild(toggleEl);
  consoleEl.appendChild(titleEl);
  if(txt===undefined) return;

  if(_.isArray(txt))
    txt = txt.join('\n');
  var block = document.createElement("pre");
  block.innerHTML='<code>'+txt+'</code>';
  hljs.highlightBlock(block);

  consoleEl.appendChild(block);
}


function logJSON(title,data,collapsed){
  return log(title,JSON.stringify(data,null,2),collapsed);
}
